home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
UPC12BS1.ZIP
/
LIB
/
SECURITY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-03
|
34KB
|
875 lines
/*--------------------------------------------------------------------*/
/* s e c u r i t y . c */
/* */
/* Security routines for UUPC/extended */
/* */
/* Copyright (c) 1991, Andrew H. Derbyshire */
/* See README.PRN for additional copyrights and restrictions */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: security.c 1.9 1993/10/03 20:37:34 ahd Exp $
*
* Revision history:
* $Log: security.c $
* Revision 1.9 1993/10/03 20:37:34 ahd
* Lower case all strings loaded into directory array
*
* Revision 1.8 1993/09/20 04:38:11 ahd
* TCP/IP support from Dave Watt
* 't' protocol support
* OS/2 2.x support
*
* Revision 1.7 1993/08/03 03:11:49 ahd
* Make missing directories non-fatal
*
* Revision 1.6 1993/05/06 03:41:48 ahd
* Use NULL to denote current directory, not "."
*
* Revision 1.5 1993/04/11 00:31:04 ahd
* Global edits for year, TEXT, etc.
*
* Revision 1.4 1993/03/06 22:48:23 ahd
* Re-do compare of sort to void bug in some qsort() functions
*
* Revision 1.3 1992/11/22 20:58:55 ahd
* Normalize directories as read
* Use strpool to allocate const strings
*
* Revision 1.2 1992/11/19 02:57:31 ahd
* drop rcsid
*
* Revision 1.1 1992/11/16 05:00:26 ahd
* Initial revision
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <sys/types.h> /* Only really needed for MS C */
#include <sys/stat.h>
#include <time.h>
#include <direct.h>
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "hostable.h"
#include "security.h"
#include "usertabl.h"
#include "expath.h"
#include "hlib.h"
/*--------------------------------------------------------------------*/
/* Local defines */
/*--------------------------------------------------------------------*/
static boolean InitEntry( char *buf, const char *fname);
static size_t InitDir( char *directories,
const REMOTE_ACCESS access,
const boolean grant,
struct HostSecurity *anchor,
size_t max_elements );
int dircmp( const void *a , const void *b );
/*--------------------------------------------------------------------*/
/* Global varables */
/*--------------------------------------------------------------------*/
struct HostSecurity *securep = NULL;
static struct HostSecurity *default_security = NULL;
static char drive[] = "C:";
currentfile();
/*--------------------------------------------------------------------*/
/* L o a d S e c u r i t y */
/* */
/* Initialize security processing; returns TRUE if security */
/* initialized, otherewise FALSE */
/*--------------------------------------------------------------------*/
boolean LoadSecurity( void )
{
char fname[FILENAME_MAX];
char buffer[BUFSIZ*4]; /* Allows around 2K for the data */
struct HostTable *hostp;
FILE *stream;
/*--------------------------------------------------------------------*/
/* Generate a filename for the permissions file and open it */
/*--------------------------------------------------------------------*/
mkfilename(fname, E_confdir, PERMISSIONS);
stream = FOPEN( fname, "r",TEXT_MODE);
if ( stream == NULL ) /* Did the file open? */
{ /* No --> Report failure to caller */
printerr( fname );
return FALSE;
} /* ( stream == NULL ) */
/*--------------------------------------------------------------------*/
/* Get current drive for normalizing names */
/*--------------------------------------------------------------------*/
getcwd( buffer, sizeof buffer );
*drive = *buffer;
/*--------------------------------------------------------------------*/
/* Begin processing the PERMISSIONS file */
/*--------------------------------------------------------------------*/
while ( !feof( stream ) )
{
char *next = buffer;
/*--------------------------------------------------------------------*/
/* Build up the buffer to be processed */
/*--------------------------------------------------------------------*/
*next = '\0';
while( fgets( next, sizeof buffer - strlen(next), stream ) != NULL)
{
if ((*next == '#') || (*next == '\n'))
{
*next = '\0';
continue;
}
next = next + strlen( next ) - 1;
if (*next == '\n')
*next-- = '\0';
else if (!feof( stream )) /* Did we hit EOF? */
{ /* No --> Presume the buffer overflowed*/
printmsg(0,"LoadSecurity: buffer overflow while reading %s",
fname);
fclose( stream );
return FALSE;
}
while( isspace( *next )) /* Dump trailing white space */
*next-- = '\0';
if (*next == '\\')
*next = '\0';
else
break;
} /* while( fgets( next, sizeof available, stream )) != NULL)) */
/*--------------------------------------------------------------------*/
/* Done read the data; verify we had no errors */
/*--------------------------------------------------------------------*/
if (ferror( stream ))
{
printerr( fname );
clearerr( stream );
return FALSE;
} /* if */
/*--------------------------------------------------------------------*/
/* Build entries for one permissions entry */
/*--------------------------------------------------------------------*/
printmsg(10,"Buffer is \"%s\"", buffer );
if ((*next != '\0') && !InitEntry( buffer , fname))
{
fclose( stream );
return FALSE;
}
} /* while ( !feof( stream ) ) */
/*--------------------------------------------------------------------*/
/* Initialize local host entry */
/*--------------------------------------------------------------------*/
hostp = checkname( E_nodename );
if ( hostp == NULL )
panic();
hostp->hsecure = malloc( sizeof *hostp->hsecure );
checkref( hostp->hsecure );
memset( hostp->hsecure , '\0', sizeof *hostp->hsecure);
/* Clear pointers */
hostp->hsecure->local = TRUE;
/*--------------------------------------------------------------------*/
/* Return to caller */
/*--------------------------------------------------------------------*/
fclose( stream );
return TRUE;
} /* LoadSecurity */
/*--------------------------------------------------------------------*/
/* I n i t i a l i z e